package com.ruoyi.common.enums.wecom;


import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum WecomMsgCallBackTagChangeTypeEnum {
    TAG_CREATE("create", "企业客户标签创建事件"),
    TAG_UPDATE("update", "企业客户标签变更事件"),
    TAG_DELETE("delete", "企业客户标签删除事件"),
    TAG_SHUFFLE("shuffle", "企业客户标签重排事件"),
    ;

    private final String code;
    private final String desc;


    private static final Map<String, WecomMsgCallBackTagChangeTypeEnum> ENUM_MAP;

    static {
        WecomMsgCallBackTagChangeTypeEnum[] values = values();
        Map<String, WecomMsgCallBackTagChangeTypeEnum> enToCn = new HashMap<>(values.length);
        for (WecomMsgCallBackTagChangeTypeEnum value : values) {
            enToCn.put(value.getCode(), value);
        }
        ENUM_MAP = Collections.unmodifiableMap(enToCn);
    }

    /**
     * 根据类型查找枚举
     */
    public static WecomMsgCallBackTagChangeTypeEnum getEnumByType(String type) {
        WecomMsgCallBackTagChangeTypeEnum wecomMsgCallBackTagChangeTypeEnum = ENUM_MAP.get(type);
        if (ObjectUtil.isEmpty(wecomMsgCallBackTagChangeTypeEnum)) {
            throw new RuntimeException("类型有误");
        }
        return wecomMsgCallBackTagChangeTypeEnum;
    }


}
